package com.example.demo.contorller;

import com.example.demo.Bean.Result;
import com.example.demo.service.SqlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SqlController {

    @Autowired
    private SqlService sqlService;

    @RequestMapping("/connect")
    @CrossOrigin
    public Result connect(String studentUid){
        try {
            return sqlService.connect(studentUid);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(500,e.toString());
        }
    }

    @RequestMapping("/sql")
    @CrossOrigin
    public Result sql(String sql,String studentUid){
        try {
            return sqlService.sql(sql, studentUid);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(500,e.toString());
        }
    }

    @RequestMapping("/closeConnection")
    @CrossOrigin
    public Result closeConnection(String studentUid){
        try {
            return sqlService.closeConnection(studentUid);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(500,e.toString());
        }
    }


}
